/**
 *  Copyright (C) 2008 Richard Hall
 *
 *  This program is free software; you can redistribute it and/or modify it under the terms of the 
 *  GNU General Public License as published by the Free Software Foundation; either version 3 of the 
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
 *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *  See the GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along with this program; if not, 
 *  see <http://www.gnu.org/licenses>.
 *
 *  Additional permission under GNU GPL version 3 section 7
 *
 *  If you modify this Program, or any covered work, by linking or combining it with [name of library] 
 *  (or a modified version of that library), containing parts covered by the terms of 
 *  [name of library's license], the licensors of this Program grant you additional permission to 
 *  convey the resulting work. {Corresponding Source for a non-source form of such a combination shall 
 *  include the source code for the parts of [name of library] used as well as that of the 
 *  covered work.}
 *
 * 
 */

import com.gpsmedia.control.GPS2Google;
import com.gpsmedia.utils.NmeaDataCollector;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *A demonstration file to show how the API can be used and also to show a couple of the 
 * testing methods that I employed during implementation.
 * 
 * @author Richard Hall
 */
public class GPSAPIDemo {

    /**
    * Performs a series of tests against the test data supplied with varying
     * DOP values for both kml files using altitude and those not using altitude. 
    * 
    */
    public void checkDOPValueChanges() {
        try {
            //
            GPS2Google gg = new GPS2Google();
            String inputfilevalue = "./Log Test Data/Test1/20071214204331_NMEA0183.log";
            String outputfilevalue = "./Test Results/testDOP0AltTrue.kml";
            String picFolder = "./Picture Test Data/Test 1/";
            String audioFolder = "./Audio Test Data/Test 1/";
            Calendar picRealTime = Calendar.getInstance();
            picRealTime.clear();
            //12-1 is down to java months starting at 0
            picRealTime.set(2007, 12-1, 14, 20, 48, 32);

            Calendar audioRealTime = Calendar.getInstance();
            audioRealTime.clear();
            //12-1 is down to java months starting at 0
            audioRealTime.set(2007, 12-1, 14, 20, 48, 50);
            TimeZone outputTimeZone = TimeZone.getDefault();
            outputTimeZone.setID("GMT");
            String googleUserName = "";
            char[] googlePassword = "".toCharArray();
            String bliptvUserName = "";
            char[] bliptvPassword = "".toCharArray();
            double DOPValue = 0;
            boolean includeAlt = true;

            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP0");
            gg.readdata();
            
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 1;
            outputfilevalue = "./Test Results/testDOP1AltTrue.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP1");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 2;
            outputfilevalue = "./Test Results/testDOP2AltTrue.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP2");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 3;
            outputfilevalue = "./Test Results/testDOP3AltTrue.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP3");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 4;
            outputfilevalue = "./Test Results/testDOP4AltTrue.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP4");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 5;
            outputfilevalue = "./Test Results/testDOP5AltTrue.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP5");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 6;
            outputfilevalue = "./Test Results/testDOP6AltTrue.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP6");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();


            DOPValue = 7;
            outputfilevalue = "./Test Results/testDOP7AltTrue.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP7");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 8;
            outputfilevalue = "./Test Results/testDOP8AltTrue.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP8");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 9;
            outputfilevalue = "./Test Results/testDOP9AltTrue.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP9");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false, null);
            gg.writedata();

            DOPValue = 10;
            outputfilevalue = "./Test Results/testDOP10AltTrue.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "AltDOP10");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            includeAlt = false;
            DOPValue = 0;
            outputfilevalue = "./Test Results/testDOP0AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP0");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 1;
            outputfilevalue = "./Test Results/testDOP1AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP1");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 2;
            outputfilevalue = "./Test Results/testDOP2AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP2");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 3;
            outputfilevalue = "./Test Results/testDOP3AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP3");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 4;
            outputfilevalue = "./Test Results/testDOP4AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP4");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 5;
            outputfilevalue = "./Test Results/testDOP5AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP5");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 6;
            outputfilevalue = "./Test Results/testDOP6AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP6");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();


            DOPValue = 7;
            outputfilevalue = "./Test Results/testDOP7AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP7");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 8;
            outputfilevalue = "./Test Results/testDOP8AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP8");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 9;
            outputfilevalue = "./Test Results/testDOP9AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP9");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();

            DOPValue = 10;
            outputfilevalue = "./Test Results/testDOP10AltFalse.kml";
            gg.setparams(inputfilevalue, outputfilevalue, picFolder, audioFolder, picRealTime, audioRealTime, outputTimeZone, googleUserName, googlePassword, bliptvUserName, bliptvPassword, DOPValue, includeAlt, "NoAltDOP10");
            gg.readdata();
            gg.selectAudio(false,null);
            gg.selectPics(false,null);
            gg.writedata();





        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
    * Test the NmeaDataCollector class against the test data supplied and 
     * prints out the results to the terminal 
    */
    public void checkNmeaDataCollector() {

        try {
            NmeaDataCollector nd = new NmeaDataCollector("./Log Test Data/Test 1/20071214204331_NMEA0183.log", 0, true);
            nd.findNmeaSentenceOrder();
            nd.readdata();
            nd.printData();
        } catch (Exception ex) {
            Logger.getLogger(NmeaDataCollector.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    /**
    * Main method so this class can be run for demonstration purposes.
     * 
    */
    public static void main(String[] args) {
        GPSAPIDemo demo = new GPSAPIDemo();
        demo.checkDOPValueChanges();
        demo.checkNmeaDataCollector();
    }
}

    
    